package com.wang.springbootinit.sparkAi;

import cn.hutool.core.util.ObjectUtil;
import io.github.briqt.spark4j.model.SparkSyncChatResponse;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 星火Ai分析数据模型
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
public class AiAnalyseModel {
    /**
     * 回答结果
     */
    private String content;

    /**
     * 提问消耗的token数量
     */
    private Integer promptTokens;

    /**
     * 回答所消耗的token数量
     */
    private Integer completionTokens;

    /**
     * 此次会话消耗token总数
     */
    private Integer totalTokens;

    /**
     * 此次会话是否成功
     */
    private Boolean isSuccess;

    /**
     * 异常信息
     */
    private String exceptionContent;

    public AiAnalyseModel(SparkSyncChatResponse chatResponse){
        this.content = chatResponse.getContent();
        this.isSuccess = chatResponse.isOk();
        if(ObjectUtil.isNotNull(chatResponse.getTextUsage())){
            this.promptTokens = chatResponse.getTextUsage().getPromptTokens();
            this.completionTokens = chatResponse.getTextUsage().getCompletionTokens();
            this.totalTokens = chatResponse.getTextUsage().getTotalTokens();
        }
        if(!chatResponse.isOk()){
            this.exceptionContent = chatResponse.getException().toString();
        }
    }
}
